﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serenity.Utility
{
    public class CodeHelper
    {
        public static string GenerateCode(int codeLength, int editLength, string prefix, int count)
        {
            var cutLength = codeLength - editLength;
            var formatCode = "D" + codeLength;
            if (!string.IsNullOrWhiteSpace(prefix))
            {
                formatCode = "D" + (codeLength - Math.Min(cutLength, prefix.Length));
                prefix = prefix.Substring(0, Math.Min(cutLength, prefix.Length)) + count.ToString(formatCode);
                return prefix.ToUpper();
            }
            return 1.ToString(formatCode);
        }
    }
}
